IF OBJECT_ID(N'GetUserArea', N'P') IS NULL
BEGIN
    EXEC (
             'CREATE PROCEDURE [dbo].[GetUserArea] AS BEGIN SELECT 1 END'
         )
END
GO

ALTER PROCEDURE GetUserArea(@UserId INT)
AS
BEGIN
	DECLARE @DiaosId INT
	DECLARE @UserTypeId INT
	SELECT @DiaosId = ut.Id FROM dbo.UserType ut WHERE ut.Name = 'Diaos'
	SELECT @UserTypeId = u.UserTypeId FROM dbo.Users u WHERE u.Id = @UserId
	
	-- Check If the user is a diaos
	IF(@UserTypeId = @DiaosId)
	BEGIN
		SELECT * FROM dbo.RequestArea ra WHERE ra.Id IN (SELECT ua.AreaId
		                                                  FROM dbo.UserArea ua WHERE ua.UserId = @UserId)
	END
END
GO	